<?php

/*

* Trivia (trivia_play.php)

*/

$page_title = "Trivia";
$rank_check = 1;
include "header.inc.php";

print "$openHTML";

$get_game_info = fetch("SELECT * FROM trivia_records WHERE userid = '$userid' AND game = '$game' AND trivia_game = '$trivia_game'");

if (!$get_game_info[id])
{
	mysql_query("INSERT INTO trivia_records VALUES ('','$userid','$trivia_game','0','0','$game')");
	$get_game_info = fetch("SELECT * FROM trivia_records WHERE userid = '$userid' AND game = '$game' AND trivia_game = '$trivia_game'");
}
if ($get_game_info[playagain] > $timestamp)
{
	$timeleft = $get_game_info[playagain] - $timestamp;
	$timeleft = round($timeleft / 3600);
	die("Please play again in $timeleft hours.");
}

$get_question = fetch("SELECT * FROM trivia_questions WHERE trivia_game = '$trivia_game' AND game = '$game' AND id > '$get_game_info[last_question]' ORDER BY id");

if (!$get_question[id])
{
	mysql_query("UPDATE trivia_records SET playagain = '$timestamp+86400' WHERE userid = '$userid' AND game = '$game' AND trivia_game = '$trivia_game'");
	mysql_query("UPDATE trivia_records SET last_question = '0' WHERE userid = '$userid' AND game = '$game' AND trivia_game = '$trivia_game'");
	die("Please play again in 24 hours.$closeHTML");
}

$answers = array("<input type=radio name=answer value=1>$get_question[answer1]","<input type=radio name=answer value=2>$get_question[answer2]");

if ($get_question[answer3])
{
	$answers = array("<input type=radio name=answer value=1>$get_question[answer1]","<input type=radio name=answer value=2>$get_question[answer2]","<input type=radio name=answer value=3>$get_question[answer3]");
}
if ($get_question[answer4])
{
	$answers = array("<input type=radio name=answer value=1>$get_question[answer1]","<input type=radio name=answer value=2>$get_question[answer2]","<input type=radio name=answer value=3>$get_question[answer3]","<input type=radio name=answer value=4>$get_question[answer4]");
}

$num_answers = count($answers);

echo "<form action=trivia_play.pro.php?game=$game&trivia_game=$trivia_game method=POST><p><input type=hidden name=question value=$get_question[id]>$get_question[question]</p>";

for ($x = 0; $x < $num_answers; $x++)
{
	echo "<p>$answers[$x]</p>";
}

echo "<p><input type=submit value=Submit></p></form>";

print "$closeHTML";

?>